﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_Model.Pay
{
    /// <summary>
    /// 购物车更新参数
    /// </summary>
    public class ShoppingUpdateParams : PayUser
    {
        /// <summary>
        /// 【必填】商品信息
        /// </summary>
        [Required(ErrorMessage ="商品ID不能为空")]
        public List<ShoppingUpdateParamsCommodityId> CommodityIds { get; set; }
        
    }
    /// <summary>
    /// 购物车更新参数中商品信息
    /// </summary>
    public class ShoppingUpdateParamsCommodityId:IPayCommodityInfo,IValidatableObject
    {
        /// <summary>
        /// 【必填】商品ID
        /// </summary>
        [Required(ErrorMessage = "商品ID不能为空")]
        public int? CommodityId { get; set; }
        /// <summary>
        /// 【必填】期限；1（一个月）、3（三个月）、6（六个月）12（一年）
        /// </summary>
        [Required(ErrorMessage = "期限不能为空")]
        public int? PurchasePeriod { get; set; }
        /// <summary>
        /// 【必填】类别；1更新、2删除
        /// </summary>
        [Required(ErrorMessage = "类别不能为空")]
        [Range(1, 2, ErrorMessage = "类别无效，必须是：1或2其中之一")]
        public int? Type { get; set; }

        /// <summary>
        /// 规格列表
        /// <br/>
        /// 2022-04-09：禅道285号需求添加
        /// </summary>
        public List<SpecParamModel> Specs { get; set; }

        /// <summary>
        /// 参数验证
        /// </summary>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            ShoppingUpdateParamsCommodityId shoppingUpdateParams = validationContext.ObjectInstance as ShoppingUpdateParamsCommodityId;
            if (shoppingUpdateParams != null)
            {
                if (PurchasePeriod != null && !PurchasePeriodEnum.CheckPurchasePeriod(PurchasePeriod.Value))
                {
                    yield return new ValidationResult("商品购买期限值无效，必须是：1、3、6、12其中之一", new string[] { "PurchasePeriod" });
                }
            }
        }
    }
}
